/**
 * @namespace
 */
aws.pathes = {
	'?': {
		name: 'Map',
		description: 'Shows map of all available pathes',
		immediate: true,
		onEnter: {
			description: 'Show information',
			exec: function() {
				var container = $('<div />', {
					"id": "aws-map"
				}).appendTo('body');
				
				function addWaypoints(waypoints, cls, prek) {
					cls = cls || '';
					prek = prek || '';
					var html = '<ul class="' + cls + '">';
					if (typeof waypoints.value != 'undefined') {
						html += '<li>value</li>';
					} else {
						$.each(waypoints, function(k, waypoint) {
							html += '<li><div class="container"><span class="waypoint-name">' + waypoint.name + ' ';
							if (waypoint.next && typeof waypoint.next.value != 'undefined') {
								html += '<span class="value">+ </span>';
							}
							html += '<span class="keys"><em>' + prek + ' </em><strong>' + k +  '</strong></span>';
							html += '</span>';
							html += '<span class="waypoint-description">' + waypoint.description + '</span></div>';
							if (waypoint.next && typeof waypoint.next.value == 'undefined') {
								html += addWaypoints(waypoint.next, null, prek + k);
							}
							html += '</li>';
						});
					}
					html += '</ul>';
					return html;
				};
				
				container.append(addWaypoints(aws.pathes, 'pathes') );
				
				$('li', container).click(function(e) {
					$(document).trigger('keypress.aws', [27, 'special']);
					$.each($('span.keys:eq(0)', this).text(), function() {
						$(document).trigger('keypress.aws', [this.charCodeAt(0), 'normal']);
					});
					e.stopPropagation();
				});
				
				$(document).keydown(function(e) {
					if (e.keyCode == 27) {
						container.remove();
					}
				});
			},
			isAvailable: function() {
				return true;
			}
		}
	}
};
